package com.lfnyxy.service.imp;

import com.lfnyxy.dao.ProductDao;
import com.lfnyxy.entity.ProductEntity;
import com.lfnyxy.query.ProductQuery;
import com.lfnyxy.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProductServiceImp implements ProductService {
    @Autowired
    public ProductDao productDao;

    public int CreateItem(ProductEntity entity) {
        if (entity != null) {
            return productDao.CreateItem(entity);
        } else {
            return 0;
        }
    }

    public int UpdateItem(ProductEntity entity) {
        if (entity != null) {
            return productDao.UpdateItem(entity);
        } else {
            return 0;
        }
    }

    public List <ProductEntity> QueryPageList(ProductQuery query) {
        int count = productDao.QueryPageListCount(query);
        query.setTotal(count);
        return productDao.QueryPageList(query);
    }

    public List <ProductEntity> QueryAll() {
        return productDao.QueryAll();
    }

    public ProductEntity QueryItem(int Id) {
        if (Id > 0) {
            return productDao.QueryItem(Id);
        } else {
            return null;
        }
    }

    public int DeleteItem(int Id) {
        if (Id > 0) {
            return productDao.DeleteItem(Id);
        } else {
            return 0;
        }
    }

    private boolean CheckIsExist(ProductEntity entity) {
        if (entity != null) {
            return productDao.CheckIsExist(entity) > 0;
        } else {
            return false;
        }
    }
}